package com.mad.base.manager;

import com.mad.base.objects.player.EPlayerType;
import com.mad.base.objects.ships.EShipType;
import com.mad.base.system.EDirection;
import com.mad.base.system.ID;

public class GameManager extends Manager {

	protected static final int GRID_WIDTH = 10, GRID_HEIGHT = GRID_WIDTH ; 
	
	private PlayerManager player1, player2 ; 
	
    public PlayerManager getPlayer1()
    {
        return player1;
    }

    public PlayerManager getPlayer2()
    {
        return player2;
    }

    public PlayerManager getHumanPlayerManager(){
       return this.getPlayerManagerByPlayerType( EPlayerType.HUMAN ); 
    }
    
    public PlayerManager getComputerPlayerManager(){
        return this.getPlayerManagerByPlayerType( EPlayerType.COMPUTER ); 
    }
    
    public PlayerManager getPlayerManagerByPlayerType(EPlayerType pType){
        return (player1.getPlayerType() == pType) ? player1 : player2 ; 
    }
    
    public GameManager() {
		super(); 
		this.init(null); 
	}

    public void playerSpawnsNewShip(EPlayerType pType, EShipType sType, ID bowID, EDirection dir){
        this.getPlayerManagerByPlayerType( pType ).spawnNewShip( sType, bowID, dir ); 
    }
    
	@Override
	public void init(Object o) {
	    this.player1 = new PlayerManager(this, EPlayerType.HUMAN); 
        this.player2 = new PlayerManager(this, EPlayerType.COMPUTER); 
	    this.player1.init( o ); 
	    this.player2.init( o ); 
	}

	@Override
	public void exit(Object o) {
        this.player1.exit( o ); 
        this.player2.exit( o ); 
	}

	@Override
	public void update(Object o) {
        this.player1.update( o ); 
        this.player2.update( o ); 
	}

}
